package jmu.cze.config;

import jmu.cze.interceptor.AdminInterceptor;
import jmu.cze.interceptor.CustomerInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login").setViewName("user/login");
        registry.addViewController("/register").setViewName("user/register");
        registry.addViewController("/admin").setViewName("index");
        registry.addViewController("/info").setViewName("info");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AdminInterceptor()).addPathPatterns("/admin/**");
        registry.addInterceptor(new CustomerInterceptor())
                .addPathPatterns("/book/**")
                .addPathPatterns("/user/update")
                .addPathPatterns("/payment/**").addPathPatterns("/doPayment");
    }
}
